package com.of.controller;

import com.of.pojo.Role;
import com.of.pojo.User;
import com.of.service.RoleService;

import com.of.vo.PageResult;
import com.of.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/list")
    public SysResult findRoleList(PageResult pageResult) {//3
        pageResult = roleService.findRoleList(pageResult);//+2
        return SysResult.success(pageResult);
    }

    @PutMapping("/status/{id}/{status}")
    public SysResult updateStatus(Role role) {
        roleService.updateStatus(role);
        return SysResult.success();
    }
    @PutMapping("/updateRole")
    public SysResult updateRole(@RequestBody Role role){
        roleService.updateRole(role);
        return SysResult.success();
    }
    @GetMapping("/{id}")
    public SysResult findRoleById(@PathVariable Integer id){
        Role role = roleService.findRoleById(id);
        return SysResult.success(role);
    }

    @PostMapping("/addRole")
    public SysResult saveUser(@RequestBody Role role){
        roleService.saveRole(role);
        return SysResult.success();
    }
    @DeleteMapping("/{id}")
    public SysResult deleteRoleById(@PathVariable Integer id){
        roleService.deleteRoleById(id);
        return SysResult.success();
    }

}
